package com.example.mysdktest.activities;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.mysdktest.R;
import com.example.mysdktest.base.BaseActivity;
import com.xm9m.ibczy.dsp.utils.AntLog;

/**
 * Created by baichuan on 2016/11/28.
 */

public class AntAddView extends BaseActivity implements View.OnClickListener {
    private LinearLayout root;
    private Button obt;

    @Override
    public int getLaout() {
        return R.layout.ac_add_view_layout;
    }

    @Override
    public void initView() {
        root = (LinearLayout) findViewById(R.id.ac_add_view_root);
        obt = (Button) findViewById(R.id.ac_add_view_obt001);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        root.setOnClickListener(this);
        obt.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ac_add_view_root:
               // addViews();
                addViews1();
                break;
            case R.id.ac_add_view_obt001:
                changeSize();
                break;
        }
    }

    private void addViews1() {

        LinearLayout linearLayout=new LinearLayout(this);

        linearLayout.setBackgroundColor(Color.RED);
        linearLayout.setMinimumWidth(200);
        linearLayout.setMinimumHeight(200);
        AntLog.i("isNull="+(linearLayout.getLayoutParams()==null));
        root.addView(linearLayout);

    }

    private void changeSize() {
        ViewGroup.LayoutParams par = obt.getLayoutParams();
        par.width=100;
        par.height=50;
        obt.setLayoutParams(par);
    }

    private void addViews() {
        Button obt = new Button(this);
        obt.setText("adds view ");
        LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.width = 100;
        params.height = 100;
        obt.setLayoutParams(params);
        obt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
                layoutParams.width=v.getWidth()+20;
                v.setLayoutParams(layoutParams);
            }
        });

        root.addView(obt);
    }
}
